package com.anyisn.anyflickr.shell.view
{
	import com.anyisn.anyflickr.modules.PhotoInfo.PhotoInfoModule;
	import com.anyisn.anyflickr.modules.PhotoInfo.view.component.PhotoInfoWindow;
	import com.anyisn.anyflickr.shell.ShellFacade;
	import com.anyisn.anyflickr.shell.model.PhotoProxy;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class PhotoInfoModuleMediator extends Mediator
	{
		public function PhotoInfoModuleMediator(viewComponent:PhotoInfoModule)
		{
			super(viewComponent.getID(), viewComponent);
		}
		
		override public function onRegister():void
		{
			photoInfoModule.exportPhotoInfoWindow();
		}
		
		override public function listNotificationInterests():Array
		{
			return [
					ShellFacade.CLOSE_PHOTO_INFO_WINDOW
				   ];	
		}
		
		override public function handleNotification( note:INotification ):void
		{
			switch( note.getName() )
			{
				case  ShellFacade.CLOSE_PHOTO_INFO_WINDOW:
					var win:PhotoInfoWindow = note.getBody() as PhotoInfoWindow;
					if(win.moduleID == photoInfoModule.getID()) {
						viewComponent = null;
						facade.removeMediator(this.getMediatorName());
						var photoP:PhotoProxy = facade.retrieveProxy(PhotoProxy.NAME) as PhotoProxy;
						photoP.hasPIWin = false;
					}
					break;
			}
		}
		
		private function get photoInfoModule():PhotoInfoModule
		{
			return viewComponent as PhotoInfoModule;
		}
	}
}